@using viBook.Models
@model Chapter
<script src="../../Scripts/jquery-1.4.4.js" type="text/javascript"> </script>
<link href="../../Scripts/uploadify/uploadify.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/uploadify/swfobject.js" type="text/javascript"> </script>
<script src="../../Scripts/uploadify/jquery.uploadify.v2.1.4.min.js" type="text/javascript"> </script>
<div class="editor-label">
    @Html.LabelFor(model => model.ChapterName)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.ChapterName)
    @Html.ValidationMessageFor(model => model.ChapterName)
</div>
<div class="editor-label">
    @Html.LabelFor(model => model.Content)
</div>
<div class="editor-field">
    @Html.EditorFor(model => model.Content)
    @Html.ValidationMessageFor(model => model.Content)
</div>

<div class="editor-field">
    @Html.HiddenFor(model => model.BookId)
</div>
<div>
    <input type="hidden" id="fileUploadInfo" name="fileUploadInfo" />
    <input id="file_upload" name="file_upload" type="file" /></div>
<script type="text/javascript">
    $(document).ready(function() {

        // Multiple files - single input

        var bookid = @Model.BookId ;

        $("#file_upload").uploadify(
            {
                'uploader': '/Scripts/uploadify/uploadify.swf',
                'script': '@Url.Action("UploadFiles")',
                'buttonText': 'Select files',
                'multi': true,
                'scriptData': { 'path':bookid},
                'sizeLimit': 20000000,
                'cancelImg': '/Scripts/uploadify/cancel.png',
                'auto': false,
                'removeCompleted': true,
                'simUploadLimit': 1,
                'fileExt': '*.jpg;*.bmp;*.png;*.gif',
                'onError': function(a, b, c, d) {
                    if (d.status == 404)
                        alert("Could not find upload script. Use a path relative to: " + "<?= getcwd() ?>");
                    else if (d.type === "HTTP")
                        alert("error " + d.type + ": " + d.status);
                    else if (d.type === "File Size")
                        alert(c.name + " " + d.type + " Limit: " + Math.round(d.info / (1024 * 1024)) + "MB");
                    else
                        alert("error " + d.type + ": " + d.text);

                },
                'onComplete': function(event, id, fileObj, response, data) {
                    $("#fileUploadInfo").val($("#fileUploadInfo").val() + ";" + response);
                },

                'onAllComplete': function(event, queueId, fileObj, response, data) {
                    alert('files uploaded successfully!');
                    $("#CreatChapterForm").submit();

                }
            });

    });
</script>
